package MyOop04;

import java.util.Random;
import java.util.Scanner;
/**
 * 键盘输入任意字符串，打乱里面的内容
 */
public class StringPractice003 {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        System.out.println("请输入一段字符串");
//        String str = sc.next();
        String str = "asdf";
        //打乱内容
        //转成数组，下标互换
        char[] arr = str.toCharArray();
        System.out.println(arr);
        for (int i = 0; i < arr.length; i++) {
            Random r = new Random();
            int index = r.nextInt(arr.length);
            char a = arr[i];
            arr[i] = arr[index];
            arr[index] = a;
            System.out.println(arr[i]);

        }

    }

    //定义一个方法用来决定下标
    public static int xiabiao(char[] arr){
        Random r = new Random();
        int index = r.nextInt(arr.length);
        int[] a = new int[arr.length];
        a[0] = index;
        for (int i = 0; i < arr.length; i++) {
           index = r.nextInt(arr.length);
            for (int j = 0; j < a.length; j++) {
               while (index==a[j]){
                   index= r.nextInt(arr.length);
                   break;
               }
            }
        }
        return index;
    }

}
